<template>
  <div class="common-search-box">
    <div class="content" :class="{ autoHieght: isExpand }" ref="content">
      <slot ref="my-slot"></slot>
    </div>

    <div class="expand">
      <template v-if="hasMore">
        <el-button v-if="isExpand" type="text" @click="isExpand = false"
          >收起 <svg-icon icon-class="arrow-double-up"
        /></el-button>
        <el-button v-else type="text" @click="isExpand = true"
          >展开<svg-icon icon-class="arrow-double-down"
        /></el-button>
      </template>

      <el-button
        type="primary"
        icon="el-icon-search"
        size="mini"
        @click="$emit('handleQuery')"
        >查询</el-button
      >
      <el-button icon="el-icon-refresh" size="mini" @click="$emit('resetQuery')"
        >重置</el-button
      >
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isExpand: false,
      hasMore: false
    };
  },
  mounted() {
    this.hasMore = this.$refs.content.children[0].clientHeight > 47;
    window.onresize = () => {
      return (() => {
        this.hasMore = this.$refs.content.children[0].clientHeight > 47;
      })();
    };
  },
  methods: {
    handleQuery() {
      this.$emit("handleQuery")
    },
    resetQuery() {},
  },
};
</script>

<style lang="scss" scoped>
.common-search-box {
  display: flex;
  justify-content: space-between;
  padding-bottom: 5px;
  .content {
    flex: 1;
    height: 40px;
    overflow: hidden;
    transition: all 1s linear;
    -webkit-transition: all 1s linear;
  }
  .autoHieght {
    height: auto;
    transition: all 1s linear;
    -webkit-transition: all 1s linear;
  }
  .expand {
    height: 40px;
    .el-button {
      font-weight: bold;
    }
  }
}
</style>